angular.module('App').controller('index', ['$scope', '$rootScope',
    function ($scope, $rootScope) {
        //圆形图
        var time;
        function circle(txt,arg, big) {
            time = setTimeout(function () {
                var canvas = document.getElementById('canvas'),
                    cs = canvas.getContext('2d'),
                    width = canvas.width,
                    height = canvas.height;

                cs.clearRect(0, 0, width, height);
                cs.beginPath();
                cs.lineWidth = 12;
                cs.arc(100, 100, 60, 0, arg * Math.PI);
                // cs.scale(1.1,1.1);
                cs.lineCap = 'round';
                var gradient = cs.createLinearGradient(0, 0, width, height);
                gradient.addColorStop("0", "#86c1fd");
                // gradient.addColorStop("0.5","red");
                gradient.addColorStop("1", "#304ebb");
                cs.strokeStyle = gradient;
                cs.font = '14px Microsoft YaHei';
                cs.fillStyle = '#333';
                cs.fillText(txt, 90, 102);
                cs.stroke();
                // cs.closePath();
                if (!big || arg > big) {
                    clearTimeout(time);
                    return false;
                }
                return circle(txt,arg+0.1, big);
            }, 100);
        }
        circle('90%',0.3);

        canvas.onmouseenter = function (event) {
            clearTimeout(time);
            circle('90%',0.1, 1.5);
            // clearInterval(time);
            // var num = 0.1,
            //     big = 1.5;
            // time = setInterval(function () {
            //     num += 0.1;
            //     circle(num.toFixed(1));
            //     if (num > big) {
            //         clearInterval(time);
            //         return false;
            //     }

            // }, 100);
        };
//圆形图 end

        var awid = angular.element('.dbox .box1').width(),
            main_ele = document.getElementById('main'),
            css = 'width:' + parseInt(awid * 0.8) + 'px;';
        main_ele.style.cssText = css;

        angular.element(window).resize(function () {
            var awid = angular.element('.dbox .box1').width(),
            main_ele = document.getElementById('main'),
            css = 'width:' + parseInt(awid * 0.8) + 'px;';
            main_ele.style.cssText = css;
        });

        var myChart = echarts.init(main_ele);

        var data = [
            ["2000-06-05", 116],
            ["2000-06-06", 129],
            ["2000-06-07", 135],
            ["2000-06-08", 86],
            ["2000-06-09", 73],
            ["2000-06-10", 85],
            ["2000-06-11", 73],
            ["2000-06-12", 68],
            ["2000-06-13", 92],
            ["2000-06-14", 130],
            ["2000-06-15", 245],
            ["2000-06-16", 139],
            ["2000-06-17", 115],
            ["2000-06-18", 111],
            ["2000-06-19", 309],
            ["2000-06-20", 206],
            ["2000-06-21", 137],
            ["2000-06-22", 128],
            ["2000-06-23", 85],
            ["2000-06-24", 94],
            ["2000-06-25", 71],
            ["2000-06-26", 106],
            ["2000-06-27", 84],
            ["2000-06-28", 93],
            ["2000-06-29", 85],
            ["2000-06-30", 73],
            ["2000-07-01", 83],
            ["2000-07-02", 125],
            ["2000-07-03", 107],
            ["2000-07-04", 82],
            ["2000-07-05", 44],
            ["2000-07-06", 72],
            ["2000-07-07", 106],
            ["2000-07-08", 107],
            ["2000-07-09", 66],
            ["2000-07-10", 91],
            ["2000-07-11", 92],
            ["2000-07-12", 113],
            ["2000-07-13", 107],
            ["2000-07-14", 131],
            ["2000-07-15", 111],
            ["2000-07-16", 64],
            ["2000-07-17", 69],
            ["2000-07-18", 88],
            ["2000-07-19", 77],
            ["2000-07-20", 83],
            ["2000-07-21", 111],
            ["2000-07-22", 57],
            ["2000-07-23", 55],
            ["2000-07-24", 60]
        ];

        var dateList = data.map(function (item) {
            return item[0];
        });
        var valueList = data.map(function (item) {
            return item[1];
        });

    //  var   option = {
    //         // Make gradient line here
    //         visualMap: [{
    //             show: false,
    //             type: 'continuous',
    //             seriesIndex: 0,
    //             min: 0,
    //             max: 400,
    //         }],
    //         // title: [{
    //         //     left: 'center',
    //         //     text: ''
    //         // }],
    //         tooltip: {
    //             trigger: 'axis',
    //             // position: function (pt) {
    //             //     return [pt[0], '10%'];
    //             // }
    //         },
    //         xAxis: [{
    //             data: dateList
    //         }],
    //         yAxis: [{
    //             splitLine: {show: false}
    //         }],
    //         grid: [{
    //             bottom: '20px'
    //         }],
    //         series: [{
    //             type: 'line',
    //             showSymbol: false,
    //             data: valueList
    //         }]
    //     };










    var base = +new Date(1968, 9, 3);
    var oneDay = 24 * 3600 * 1000;
    var date = [];

    var data = [10];

    for (var i = 1; i < 10; i++) {
        var now = new Date(base += oneDay);
        date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
        data.push(Math.random() * 20);
    }

   var option = {
        tooltip: {
            trigger: 'axis',
            position: function (pt) {
                return [pt[0], '10%'];
            }
        },
        // title: {
        //     left: 'center',
        //     text: '大数据量面积图',
        // },
        // legend: {
        //     top: 'bottom',
        //     data:['意向']
        // },
        // toolbox: {
        //     feature: {
        //         dataZoom: {
        //             yAxisIndex: 'none'
        //         },
        //         restore: {},
        //         saveAsImage: {}
        //     }
        // },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: date,
            axisLine: {  //隐藏轴线
                show: false
            },
            axisTick: { //是否显示坐标轴刻度。
                show: false
            }
        },
        yAxis: {
            type: 'value',
            boundaryGap: [0, '100%'],
            // boundaryGap: true,
            show: false,
        },
        // dataZoom: [{
        //     type: 'inside',
        //     start: 0,
        //     end: 10
        // }, {
        //     start: 0,
        //     end: 10,
        //     handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
        //     handleSize: '80%',
        //     handleStyle: {
        //         color: '#fff',
        //         shadowBlur: 3,
        //         shadowColor: 'rgba(0, 0, 0, 0.6)',
        //         shadowOffsetX: 2,
        //         shadowOffsetY: 2
        //     }
        // }],
        series: [
            {
                name:'模拟数据',
                type:'line',
                smooth:true,
                symbol: 'none',
                sampling: 'average',
                itemStyle: {
                    normal: {
                        color: '#66c0ff'
                    }
                },
                areaStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#66c0ff'
                        }, {
                            offset: 1,
                            color: '#fff'
                        }])
                    }
                },
                data: data
            }
        ]
    };


        myChart.setOption(option);
    }]);